//
//  GRXNavigationController.m
//  1-MushroomStreet-自定义tabbar
//
//  Created by xmg on 15/12/18.
//  Copyright © 2015年 grx. All rights reserved.
//

#import "GRXNavigationController.h"

@interface GRXNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation GRXNavigationController


+(void)load{
    //获取全局导航条
    UINavigationBar *naviBar = [UINavigationBar appearanceWhenContainedIn:self, nil];
    
    //设置标题字体
    NSMutableDictionary *arr = [NSMutableDictionary dictionary];
    
    //字体
    arr[NSFontAttributeName] = [UIFont boldSystemFontOfSize:18];
    
    [naviBar setTitleTextAttributes:arr];
    
    
    //设置导航条背景图片
    // iOS9之前,如果使用了UIBarMetricsDefault,默认导航控制器的根控制器的尺寸,会少64的高度.
    // UIBarMetricsDefault:必须设置默认
    
//    [naviBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhite"] forBarMetrics:UIBarMetricsDefault];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self.interactivePopGestureRecognizer.delegate action:@selector(handleNavigationTransition:)];
    
    
    //控制手势什么时候触发
    pan.delegate = self;
    
    //全屏滑动返回
    [self.view addGestureRecognizer:pan];
    
}

#pragma mark - UIGestureRecognizerDelegate

// 控制手势是否触发
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    //如果直接返回YES,会造成假死状态(如果是根控制器就返回NO,就是不触发手势)
    return self.childViewControllers.count != 1;
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    //这里会取消系统的返回手势
    //不是根控制器才需要设置
    if (self.childViewControllers.count > 0) {
        UIBarButtonItem *item = [UIBarButtonItem itemWithNorImage:[UIImage imageNamed:@"btn_navigationbar_back"] selImage:[UIImage imageNamed:@"btn_navigationbar_back"] target:self action:@selector(backClick) norColor:[UIColor blackColor] highColor:[UIColor redColor] title:@"返回"];
        
        viewController.navigationItem.leftBarButtonItem = item;
    }
    
    //跳转
    [super pushViewController:viewController animated:animated];
}

- (void)backClick{
//    NSLog(@"返回上一个");
    [self popViewControllerAnimated:YES];
}

@end
